package com.knowif.backend.controller;

import com.github.pagehelper.PageInfo;
import com.knowif.backend.service.SpecialService;
import com.knowif.pojo.Special;
import com.knowif.pojo.SpecialExample;
import com.knowif.search.SearchCondition;
import com.knowif.system.model.RestBean;
import com.knowif.util.ExampleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：Xh
 * @date ：Created in 2019/6/5 0005 21:06
 */
@RestController
@RequestMapping("/wechat")
public class SpecialController {

    @Autowired
    private SpecialService specialService;

    @PostMapping("/special/query")
    public RestBean<?> query(@RequestBody SearchCondition searchCondition){
        try {
            SpecialExample specialExample = ExampleUtil.buildExample(new SpecialExample(), searchCondition);
            List<Special> specials = specialService.selectSpecial(specialExample, false);
            PageInfo<Special> pageInfo = new PageInfo<Special>(specials);
            return RestBean.build(RestBean.success_code, "", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return RestBean.buildError("参数错误");
        }
    }
}
